//
//  bytestring.h
//  cobalt
//
//  Created by Nicolas Godbout on 2013-08-19.
//  Copyright (c) 2013 Nicolas Godbout. All rights reserved.
//

#ifndef __cobalt__bytestring__
#define __cobalt__bytestring__

#include <cstddef>
#include <cstring>

struct ByteString {
    char*   base;       // ## TODO: change to shared pointer
    size_t  offset;
    size_t  length;
public:
    ByteString() : base(NULL), offset(0), length(0) {}
    ByteString(char* str);
    ByteString(char* str, size_t o, size_t l) : base(str), offset(o), length(l) {}
    
    operator bool() const;
    
    char* toCstr() const;
};

inline
ByteString::ByteString(char* str) {
    base = str;
    offset = 0;
    length = std::strlen(base);
}

inline
ByteString::operator bool() const {
    return (bool)length;
}

#endif /* defined(__cobalt__bytestring__) */
